package tt.dz.mvc.controller.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.system.OmsOperList;
import tt.dz.service.sys.enterpriseUserCallbackService;
import tt.dz.util.OmsConstant.MsgCodeEnum;

@Controller
public class CollBackController {
	@Autowired
	@Qualifier("enterpriseUserCallbackServiceImp")
	private enterpriseUserCallbackService callbackService;

	/**
	 * 企业账号、回调类型（1预约、2取消预约、3充电、4取消充电）、回调参数列表{数量可变} localhost://jranl =xx&
	 * chargerid =aaa& 预约回调pojo :报文流水号、电桩地址、电桩端口号、开始预约时间。
	 * 
	 * 结束预约回调pojo :报文流水号、电桩地址、电桩端口号、结束预约时间。总金额、订单号
	 * 
	 * 开始充电回调pojo :报文流水号、电桩地址、电桩端口号、开始充电时间。
	 * 
	 * 结束充电回调pojo :报文流水号、电桩地址、电桩端口号、结束充电时间。
	 * 
	 * 账单回调pojo：预约流水号、充电流水号、电桩地址、电桩端口号、总金额、订单号
	 * 预约流水号、充电流水号是有关联的，通过充电流水号查询不到预约流水号时，预约流水号可为空。
	 */
	@RequestMapping(value = "/enterpriseUser/enterpriseUserNotifyUrl")
	@ResponseBody
	public JsonCommon<?> callbackExecutive(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String account = request.getParameter("account");
		String callBackType = request.getParameter("callbackType");
		int rolltype = Integer.parseInt(callBackType);
		JsonCommon<?> json = new JsonCommon();

		String oms_msg_bespeak_jrnl = "";
		String charger_id = "";
		String port_no = "";
		String start_time = "";
		switch (rolltype) {
		case 1:

			oms_msg_bespeak_jrnl = request.getParameter("oms_msg_bespeak_jrnl");
			charger_id = request.getParameter("charger_id");
			port_no = request.getParameter("port_no");
			start_time = request.getParameter("start_time");
			json = callbackService.notifyUrlCallback(account, rolltype,
					oms_msg_bespeak_jrnl, charger_id, port_no, start_time);
			break;
		case 2:
			oms_msg_bespeak_jrnl = request.getParameter("oms_msg_bespeak_jrnl");
			charger_id = request.getParameter("charger_id");
			port_no = request.getParameter("port_no");
			String actual_end_time = request.getParameter("actual_end_time");
			String bespeak_deal_charge = request
					.getParameter("bespeak_deal_charge");
			String order_no = request.getParameter("order_no");
			json = callbackService.notifyUrlCallback(account, rolltype,
					oms_msg_bespeak_jrnl, charger_id, port_no, actual_end_time,
					bespeak_deal_charge, order_no);
			break;
		case 3:

			oms_msg_bespeak_jrnl = request.getParameter("oms_msg_bespeak_jrnl");
			charger_id = request.getParameter("charger_id");
			port_no = request.getParameter("port_no");
			start_time = request.getParameter("start_time");
			json = callbackService.notifyUrlCallback(account, rolltype,
					oms_msg_bespeak_jrnl, charger_id, port_no, start_time);
			break;
		case 4:

			oms_msg_bespeak_jrnl = request.getParameter("oms_msg_bespeak_jrnl");
			charger_id = request.getParameter("charger_id");
			port_no = request.getParameter("port_no");
			String end_time = request.getParameter("end_time");
			json = callbackService.notifyUrlCallback(account, rolltype,
					oms_msg_bespeak_jrnl, charger_id, port_no, end_time);
			break;
		default:
			json.setCode(MsgCodeEnum.ERROR400.getMsgCode());
			json.setCode(MsgCodeEnum.ERROR400.getMsgInfo());
			break;
		}
		return json;
	}

	@RequestMapping(value = "/enterpriseUser/test")
	@ResponseBody
	public JsonCommon<?> test(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String oms_msg_bespeak_jrnl = request
				.getParameter("oms_msg_bespeak_jrnl");
		String charger_id = request.getParameter("charger_id");
		String port_no = request.getParameter("port_no");
		String start_time = request.getParameter("start_time");
		JsonCommon<String> json = new JsonCommon();

		json.setPojo(oms_msg_bespeak_jrnl);
		return json;
	}

}
